package com.by.dao.imple;

import com.by.dao.EmpDao;
import com.by.entity.Emp;
import com.by.util.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import static com.by.entity.Emp.emp;

public class EmpDaoImpl extends DButil implements EmpDao {
    Connection conn=null;
    PreparedStatement pstmt=null;
    ResultSet rs = null;
    @Override
    public List<Emp> getAllEmp() {
        List<Emp> list=new ArrayList<Emp>();
        String sql ="select * from emp";
        conn =getConn();
        try {
            pstmt= conn.prepareStatement(sql);
            rs= pstmt.executeQuery();

            while(rs.next()){
                emp=new Emp();
                emp.setEid(rs.getInt("empno"));
                emp.setEname(rs.getString("ename"));
                emp.setJod(rs.getString("job"));
                emp.setHiredate(rs.getString("hiredate"));
                emp.setSal(rs.getString("sal"));
                list.add(emp);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return list;
    }
}
